package server

import (
	"fmt"
	"strings"
	"wolongauth/config"
	"wolongauth/errhelp"

	"github.com/gofiber/fiber/v2"
)

func AddViewMap(c *fiber.Ctx) fiber.Map {
	s, err := SessionStore.Get(c)
	if !errhelp.ErrDoWithTag(err, "session get") {
		return fiber.Map{}
	}
	ShowMap := fiber.Map{}
	if s.Get("msg") != nil {
		message := fmt.Sprintf("%s", s.Get("msg"))
		message = strings.TrimSpace(message)
		if message != "" {
			ShowMap["MessageShow"] = true
			ShowMap["Message"] = message
		} else {
			ShowMap["MessageShow"] = false
		}
		s.Delete("msg")
	}
	if s.Get("errmsg") != nil {
		message := fmt.Sprintf("%s", s.Get("errmsg"))
		message = strings.TrimSpace(message)
		if message != "" {
			ShowMap["ErrMessageShow"] = true
			ShowMap["ErrMessage"] = message
		} else {
			ShowMap["ErrMessageShow"] = false
		}
		s.Delete("errmsg")
	}
	if s.Get("successmsg") != nil {
		message := fmt.Sprintf("%s", s.Get("successmsg"))
		message = strings.TrimSpace(message)
		if message != "" {
			ShowMap["SuccessMessageShow"] = true
			ShowMap["SuccessMessage"] = message
		} else {
			ShowMap["SuccessMessageShow"] = false
		}
		s.Delete("successmsg")
	}
	ShowMap["Title"] = config.GetConfig().Title
	s.Save()
	return ShowMap
}
